package org.opens.util;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;

import java.text.NumberFormat;
import java.util.Date;

/**
 * 功能描述
 *
 * @author: zhangyuming
 * @date: 2023/7/31 11:25
 */
public class DateUtil2 {

    public static String processInfo(int birthYear) {
        Date date = new Date();

        int hour = DateUtil.hour(date, true);
        int dayOfWeek = DateUtil.dayOfWeek(date);
        int dayOfMonth = DateUtil.dayOfMonth(date);
        int month = DateUtil.month(date);
        Date beginOfMonth = DateUtil.beginOfMonth(date);
        Date endOfMonth = DateUtil.endOfMonth(date);
        long betweenDay = DateUtil.betweenDay(beginOfMonth, endOfMonth, false);

        int year = DateUtil.year(date);
        int age = year - birthYear;

        NumberFormat num = NumberFormat.getPercentInstance();
        num.setMaximumIntegerDigits(4);
        num.setMaximumFractionDigits(2);

        StringBuilder builder = new StringBuilder();
        builder.append("本日进度: ").append(num.format(hour / 24.0)).append("\n")
                .append("本周进度: ").append(num.format((dayOfWeek - 1) / 6.0)).append("\n")
                .append("本月进度: ").append(num.format(dayOfMonth / betweenDay)).append("\n")
                .append("本年进度: ").append(num.format((month + 1) / 12.0)).append("\n")
                .append("人生进度: ").append(num.format(age / 80.0)).append("\n");

        return builder.toString();
    }

    public static void main(String[] args) {
        System.out.println(processInfo(1995));
        System.out.println(processInfo(1962));
    }

}
